package com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.ydkj.a37e_mall.Classes.Applicatiom.MyApplication;
import com.ydkj.a37e_mall.Classes.Fragment.ShoppingCarFg;
import com.ydkj.a37e_mall.Classes.Model.Base.GoodsInfo;
import com.ydkj.a37e_mall.Classes.Model.Request.DeleteShoppingCarReq;
import com.ydkj.a37e_mall.Classes.Model.Request.EditShoppingCarReq;
import com.ydkj.a37e_mall.Classes.Model.Request.GetShoppingCarReq;
import com.ydkj.a37e_mall.Classes.Model.Response.ShoppingCarListResp;
import com.ydkj.a37e_mall.R;
import com.ydkj.a37e_mall.Resource.Utils.Async_http_get;
import com.ydkj.a37e_mall.Resource.Utils.CommonUtil;
import com.ydkj.a37e_mall.Resource.Utils.Const;
import com.ydkj.a37e_mall.Resource.Utils.GsonImpl;
import com.ydkj.a37e_mall.Resource.Utils.SharedPreferencesUtil;
import com.ydkj.a37e_mall.Resource.View.CustomProgressDialog;
import com.ydkj.a37e_mall.Resource.View.StatusBarUtil;

import org.json.JSONObject;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import cz.msebera.android.httpclient.Header;

import static com.ydkj.a37e_mall.R.id.rb_order;


/**
 * Created by Administrator on 2017/2/7.
 */

public class ShoppingCar extends BaseActivity implements View.OnClickListener {

    private Activity mActivity;
    private SharedPreferencesUtil sharedPreferencesUtil;
    private ImageView img_back;
    private MyApplication myApplication;
    private LinearLayout hearderViewLayout;
    private PullToRefreshListView lv_my_shoppingcar;//general:普通 wholesale:批发
    private TextView tv_all_price, tv_pay_money, tv_delete;
    private ShoppingWholesaleCarListAdapter shoppingWholesaleCarListAdapter;
    private List<GoodsInfo> shoppingCarListWholesaleInfoList;
    private List<GoodsInfo> intentList;

    private int order_code = 0;//订单状态:1为普通订单，2为批发订单
    private static final int LOAD = 0;// 加载
    private static final int REFRESH = 1;// 刷新
    private static final int MORE = 2;// 更多
    private String secret;
    private int isWholesale; // 普通订单
    private int num;//打钩的个数
    private double all_price;
    private double all_integral;
    private TextThread textThread = new TextThread();
    private List<String> idList;
    DecimalFormat df = new DecimalFormat("0.00");
    private boolean is_edit = false;
    private int login_flag = 0;


    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 1:
                    tv_delete.setText("删除" + num + "项");
                    tv_pay_money.setText("结算" + num + "项");
                    tv_all_price.setText("" + df.format(all_price));
                    break;
                case 2:

                    break;
            }
        }
    };

    private class TextThread extends Thread {
        @Override
        public void run() {
            Message message = new Message();
            message.what = 1;
            mHandler.sendMessage(message);
        }
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.shoppingcar_fragment);
        mActivity = this;
//        initWindow();
        init();

    }


    private void initWindow() {
        StatusBarUtil.setColor(mActivity, getResources().getColor(R.color.A000000));
    }

    private void init() {
        new TextThread().start();
        sharedPreferencesUtil = SharedPreferencesUtil.getInstance(mActivity);
        myApplication = MyApplication.getInstance();
        idList = new ArrayList<String>();
        lv_my_shoppingcar = (PullToRefreshListView) mActivity.findViewById(R.id.lv_my_shoppingcar);
        tv_all_price = (TextView) mActivity.findViewById(R.id.tv_all_price);
        tv_pay_money = (TextView) mActivity.findViewById(R.id.tv_pay_money);
        tv_delete = (TextView) mActivity.findViewById(R.id.tv_delete);
        img_back= (ImageView) mActivity.findViewById(R.id.img_back);
        img_back.setVisibility(View.VISIBLE);

        shoppingCarListWholesaleInfoList = new ArrayList<GoodsInfo>();
        intentList = new ArrayList<GoodsInfo>();

        shoppingWholesaleCarListAdapter = new ShoppingWholesaleCarListAdapter(shoppingCarListWholesaleInfoList);
        lv_my_shoppingcar.setAdapter(shoppingWholesaleCarListAdapter);

        lv_my_shoppingcar.setOnRefreshListener2(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
                String label = DateUtils.formatDateTime(mActivity.getApplicationContext(), System.currentTimeMillis(),
                        DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
                refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
                GetShoppingCarList(REFRESH);
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
                String label = DateUtils.formatDateTime(mActivity.getApplicationContext(), System.currentTimeMillis(),
                        DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
                refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
                GetShoppingCarList(MORE);
            }
        });

        tv_delete.setOnClickListener(this);
        tv_pay_money.setOnClickListener(this);
        img_back.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_pay_money:
                intentList.clear();
                for (GoodsInfo dataEntity : shoppingCarListWholesaleInfoList) {
                    if (dataEntity.getCheck_code() == 1) {
                        intentList.add(dataEntity);
                    }
                }
                if (intentList.size() == 0) {
                    CommonUtil.showToast(mActivity, "请至少选择一个物品");
                } else {
                    Intent intent = new Intent(mActivity, ConfirmationOrder.class);
                    intent.putExtra("intentList", (Serializable) intentList);
                    startActivity(intent);
                }
                break;
            case R.id.tv_delete://删除
                DeleteShoppingCarListNumber();
                break;
            case R.id.img_back:
                finish();
                break;
        }
    }

    private class ShoppingWholesaleCarListAdapter extends BaseAdapter {
        private List<GoodsInfo> shoppingCarList;

        private ShoppingWholesaleCarListAdapter(List<GoodsInfo> shopping_car_red) {
            if (shopping_car_red == null) {
                shopping_car_red = new ArrayList<GoodsInfo>();
            }
            shoppingCarList = shopping_car_red;
        }

        @Override
        public int getCount() {
            return shoppingCarList.size();
        }

        @Override
        public GoodsInfo getItem(int position) {
            return shoppingCarList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder vh = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(mActivity).inflate(R.layout.shoppingcar_fragment_wholesale_listitem, null);
                vh = new ViewHolder();
                vh.rly_general = (RelativeLayout) convertView.findViewById(R.id.rly_general);
                vh.rb_order = (CheckBox) convertView.findViewById(R.id.rb_order);
                vh.tv_edit = (TextView) convertView.findViewById(R.id.tv_edit);
                vh.lly_shoppingcar_list = (LinearLayout) convertView.findViewById(R.id.lly_shoppingcar_list);
                vh.cb_choose = (CheckBox) convertView.findViewById(R.id.cb_choose);
                vh.img_shoppingcar_pic = (ImageView) convertView.findViewById(R.id.img_shoppingcar_pic);
                vh.tv_brand_name = (TextView) convertView.findViewById(R.id.tv_brand_name);
                vh.tv_product_price = (TextView) convertView.findViewById(R.id.tv_product_price);
                vh.tv_postage = (TextView) convertView.findViewById(R.id.tv_postage);
                vh.tv_product_size = (TextView) convertView.findViewById(R.id.tv_product_size);
                vh.tv_number_less = (TextView) convertView.findViewById(R.id.tv_number_less);
                vh.et_buy_number = (EditText) convertView.findViewById(R.id.et_buy_number);
                vh.tv_number_add = (TextView) convertView.findViewById(R.id.tv_number_add);

            } else {
                vh = (ViewHolder) convertView.getTag();
            }
            convertView.setTag(vh);
            convertView.setClickable(true);

            vh.tv_brand_name.setText(getItem(position).getName());
            vh.tv_product_price.setText(getItem(position).getPrice());
            vh.et_buy_number.setText(getItem(position).getNumbers() + "");


            for (int i = 0; i < getItem(position).getProduct().size(); i++) {
                if (i == 0) {
                    vh.tv_product_size.setText(getItem(position).getProduct().get(i).getStandard_type() + ":"
                            + getItem(position).getProduct().get(i).getStandard_name());
                } else {
                    vh.tv_product_size.setText(vh.tv_product_size.getText().toString() + "\n" + getItem(position).getProduct().get(i).getStandard_type() + ":"
                            + getItem(position).getProduct().get(i).getStandard_name());
                }
            }


            ImageLoader.getInstance().displayImage(getItem(position).getThumb(), vh.img_shoppingcar_pic, displayImageOptions);

            vh.tv_postage.setText("(包邮)");

            if (position == 0) {
                vh.rly_general.setVisibility(View.VISIBLE);
            } else {
                vh.rly_general.setVisibility(View.GONE);

            }

            if (getItem(position).getCheck_code() == 0) {
                vh.cb_choose.setChecked(false);
            } else if (getItem(position).getCheck_code() == 1) {
                vh.cb_choose.setChecked(true);
            }

            if (getItem(position).getShowStatus() == 0) {
                vh.rb_order.setChecked(false);
            } else if (getItem(position).getShowStatus() == 1) {
                vh.rb_order.setChecked(true);
            }

            num = 0;
            for (GoodsInfo dataEntity : shoppingCarListWholesaleInfoList) {
                if (dataEntity.getCheck_code() == 1) {
                    num++;
                    Log.e("url", "num==" + num);
                }
            }


            if (is_edit == true) {
                tv_pay_money.setVisibility(View.GONE);
                tv_delete.setVisibility(View.VISIBLE);
                vh.tv_edit.setText("完成");
            } else {
                tv_pay_money.setVisibility(View.VISIBLE);
                tv_delete.setVisibility(View.GONE);
                vh.tv_edit.setText("编辑");
            }

            final ViewHolder finalVh = vh;
            vh.tv_edit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (is_edit == false) {
                        tv_pay_money.setVisibility(View.GONE);
                        tv_delete.setVisibility(View.VISIBLE);
                        finalVh.tv_edit.setText("完成");
                        is_edit = true;
                    } else {
                        tv_pay_money.setVisibility(View.VISIBLE);
                        tv_delete.setVisibility(View.GONE);
                        finalVh.tv_edit.setText("编辑");
                        is_edit = false;
                    }
                }
            });

            //查看商品详细
            vh.lly_shoppingcar_list.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mActivity, ProductDetails.class);
                    intent.putExtra("id", getItem(position).getProduct_id());
                    startActivity(intent);
                }
            });

            //全选
            final ViewHolder finalVh1 = vh;
            vh.rb_order.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                    Log.e("url", "rb_order.ischeck==>" + finalVh1.rb_order.isChecked());
//                    for (GoodsInfo dataEntity : shoppingCarListWholesaleInfoList) {
//                        if (dataEntity.getIs_wholesales() == 0) {
//
//                            dataEntity.setCheck_code(1);
//                            dataEntity.setShowStatus(1);
//                        }
//
//                    }


                    for (GoodsInfo dataEntity : shoppingCarListWholesaleInfoList) {
                        Log.e("url", "dataEntity.getIs_wholesales()==>" + dataEntity.getIs_wholesales());
                        if (finalVh1.rb_order.isChecked()) {
                            dataEntity.setCheck_code(1);
                            dataEntity.setShowStatus(1);
                        } else {
                            dataEntity.setCheck_code(0);
                            dataEntity.setShowStatus(0);
                        }
                    }
                    shoppingWholesaleCarListAdapter.notifyDataSetChanged();
                    textThread.run();
                    GetAllPrice();
                }
            });


            //添加
            vh.tv_number_add.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int i = Integer.parseInt(finalVh.et_buy_number.getText().toString().trim());
                    i++;
                    Log.e("ssss", "数量==》" + i);
                    finalVh.et_buy_number.setText(i + "");
                    EditShoppingCarListNumber(getItem(position).getId(), getItem(position).getProduct_id(), Integer.parseInt(finalVh.et_buy_number.getText().toString().trim()));

                }
            });

            //减少
            vh.tv_number_less.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int i = Integer.parseInt(finalVh.et_buy_number.getText().toString().trim());
                    if (i == 1) {
                        return;
                    } else {
                        i--;
                        finalVh.et_buy_number.setText(i + "");
                        EditShoppingCarListNumber(getItem(position).getId(), getItem(position).getProduct_id(), Integer.parseInt(finalVh.et_buy_number.getText().toString().trim()));
                    }
                }
            });


            vh.et_buy_number.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    if (actionId == InputMethodManager.HIDE_NOT_ALWAYS) {
                        Log.e("url", "et_buy_number==111");
                        return true;
                    }
                    return false;
                }
            });

            //选择
            vh.cb_choose.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    Log.e("ssss", "isChecked==>" + isChecked);
                    if (isChecked) {
                        getItem(position).setCheck_code(1);
                    }
                    if (!isChecked) {
                        getItem(position).setCheck_code(0);
                    }
                    shoppingWholesaleCarListAdapter.notifyDataSetChanged();
                    textThread.run();
                    GetAllPrice();
                }
            });

            return convertView;
        }

        public class ViewHolder {
            private RelativeLayout rly_general;
            private CheckBox rb_order;
            private TextView tv_edit;
            private LinearLayout lly_shoppingcar_list;
            private CheckBox cb_choose;
            private ImageView img_shoppingcar_pic;
            public TextView tv_brand_name, tv_product_price, tv_postage, tv_product_size, tv_number_less, tv_number_add;
            private EditText et_buy_number;
        }
    }

    private void GetAllPrice() {
        all_price = 0.00;
        all_integral = 0.00;
        for (GoodsInfo dataEntity : shoppingCarListWholesaleInfoList) {
            if (dataEntity.getCheck_code() == 1) {
                all_price = all_price + (Double.parseDouble(dataEntity.getPrice()) * Integer.parseInt(dataEntity.getNumbers()));

//                all_integral = all_integral + Double.parseDouble(dataEntity.getTotal_integral());
            }
        }
        tv_all_price.setText(df.format(all_price));
        Log.e("url", "all_price==" + all_price);
        Log.e("url", "all_integral==" + all_integral);
    }

    //获取购物车列表
    private void GetShoppingCarList(final int type) {
        GetShoppingCarReq req = new GetShoppingCarReq();
        if (myApplication.getDataEntity() == null) {
            return;
        } else {
            CustomProgressDialog.createDialog(mActivity).Show();
            req.setUuid(myApplication.getDataEntity().getUuid());
        }
        req.setPage("1");
        req.setPage_size("10");
        RequestParams params = new RequestParams();
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());
        Log.e("url", "params==" + params.toString());
        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                Log.e("url", "shoppingcarList_json1==" + response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                lv_my_shoppingcar.onRefreshComplete();
                Log.e("errno", "errno==" + errno);
                all_price = 0.00;
                all_integral = 0.00;
                num = 0;
                textThread.run();
                if (errmsg.equals("购物车空空如也")) {
                    shoppingCarListWholesaleInfoList.clear();
                    tv_delete.setVisibility(View.GONE);
                    tv_pay_money.setVisibility(View.VISIBLE);
                    shoppingWholesaleCarListAdapter.notifyDataSetChanged();
                    lv_my_shoppingcar.onRefreshComplete();
                    return;
                }

                if (errno.equals("000")) {
                    ShoppingCarListResp resp = GsonImpl.get().toObject(response.toString(), ShoppingCarListResp.class);
                    if (type == LOAD || type == REFRESH) {
                        shoppingCarListWholesaleInfoList.clear();
                        for (GoodsInfo dataEntity : shoppingCarListWholesaleInfoList) {
                            dataEntity.setCheck_code(0);
                        }
                        for (GoodsInfo dataEntity : resp.getResult().getData()) {
                            if (dataEntity.getIs_wholesales() == 0) {
                                shoppingCarListWholesaleInfoList.add(dataEntity);
                            }
                        }
                        for (GoodsInfo dataEntity : resp.getResult().getData()) {
                            if (dataEntity.getIs_wholesales() == 1) {
                                shoppingCarListWholesaleInfoList.add(dataEntity);
                            }
                        }

                    } else {
                        for (GoodsInfo dataEntity : resp.getResult().getData()) {
                            if (dataEntity.getIs_wholesales() == 0) {
                                shoppingCarListWholesaleInfoList.add(dataEntity);
                            }
                        }
                        for (GoodsInfo dataEntity : resp.getResult().getData()) {
                            if (dataEntity.getIs_wholesales() == 1) {
                                shoppingCarListWholesaleInfoList.add(dataEntity);
                            }
                        }
                    }

                    if (shoppingCarListWholesaleInfoList.size() % 10 > 0) {
                        lv_my_shoppingcar.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
                    } else {
                        lv_my_shoppingcar.setMode(PullToRefreshBase.Mode.BOTH);
                    }
                    isWholesale = 0;
                    for (GoodsInfo dataEntity : shoppingCarListWholesaleInfoList) {
                        Log.e("url", "dataEntity.getIs_wholesales()==" + dataEntity.getIs_wholesales());
                        if (dataEntity.getIs_wholesales() == 0) {
                            isWholesale++;
                        }
                        Log.e("url", "isWholesale==" + isWholesale);
                    }
                    shoppingWholesaleCarListAdapter.notifyDataSetChanged();
                    lv_my_shoppingcar.onRefreshComplete();
                } else if (errno.equals("999")) {
                    login_flag++;
                    CommonUtil.showToast(mActivity, errmsg);
                    Intent intent = new Intent(mActivity, LoginActivity.class);
                    Log.e("url", "222");
                    startActivityForResult(intent, 3);
                    shoppingCarListWholesaleInfoList.clear();
                } else {
                    shoppingCarListWholesaleInfoList.clear();
                    CommonUtil.showToast(mActivity, errmsg);
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
                CommonUtil.showToast(mActivity, "网络连接失败");
                lv_my_shoppingcar.onRefreshComplete();
            }
        });
    }

    //修改购物车（更改商品数目）
    private void EditShoppingCarListNumber(String id, String product_id, int number) {
        Log.e("ssss", "id==>" + id);
        Log.e("ssss", "product_id==>" + product_id);
        CustomProgressDialog.createDialog(mActivity).Show();
        EditShoppingCarReq req = new EditShoppingCarReq();
        req.setUuid(myApplication.getDataEntity().getUuid());
        req.setProduct_id(product_id);
        req.setNum(number + "");

        RequestParams params = new RequestParams();
        params.put("id", id);
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());
        Log.e("ssss", "idididid==>" + id);
        Log.e("ssss", "secret==>" + req.getSecret());

        AsyncHttpClient client = new AsyncHttpClient();
        client.put(Const.COMMON_ADDRESS + req.urlString() + id, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                Log.e("url", "editshoppingcar_json==" + response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errmsg.equals("购物车空")) {
                    shoppingCarListWholesaleInfoList.clear();
                    shoppingWholesaleCarListAdapter.notifyDataSetChanged();
                    return;
                }
                if (errno.equals("000")) {
                    GetShoppingCarList(REFRESH);
//                    shoppingWholesaleCarListAdapter.notifyDataSetChanged();
                } else if (errno.equals("999")) {
                    CommonUtil.showToast(mActivity, errmsg);
                    Intent intent = new Intent(mActivity, LoginActivity.class);
                    startActivityForResult(intent, 2);
                } else if (errno.equals("888")) {
                    CommonUtil.showToast(mActivity, errmsg);
//                    GetShoppingCarList(REFRESH);
                } else {
                    CommonUtil.showToast(mActivity, errmsg);
                    shoppingWholesaleCarListAdapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
                CommonUtil.showToast(mActivity, "网络连接错误");
            }
        });
    }

    //删除购物车
    private void DeleteShoppingCarListNumber() {
        idList.clear();
        for (GoodsInfo dataEntity : shoppingCarListWholesaleInfoList) {
            if (dataEntity.getCheck_code() == 1) {
                idList.add(dataEntity.getId());
            }
        }

        if (idList.size() == 0) {
            CommonUtil.showToast(mActivity, "请选择至少一种物品");
            return;
        }

        CustomProgressDialog.createDialog(mActivity).Show();
        DeleteShoppingCarReq req = new DeleteShoppingCarReq();
        req.setUuid(myApplication.getDataEntity().getUuid());

        RequestParams params = new RequestParams();
        params.put("id", CommonUtil.listToString(idList, ','));
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());
        Log.e("url", "params==" + params);
        AsyncHttpClient client = new AsyncHttpClient();
        client.put(Const.COMMON_ADDRESS + req.urlString() + CommonUtil.listToString(idList, ','), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                is_edit = false;

                Log.e("url", "delete_shoppingcar_json==" + response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errno.equals("000")) {
                    GetShoppingCarList(REFRESH);
                    shoppingWholesaleCarListAdapter.notifyDataSetChanged();
                } else if (errno.equals("999")) {
                    CommonUtil.showToast(mActivity, errmsg);
                    Intent intent = new Intent(mActivity, LoginActivity.class);
                    startActivityForResult(intent, 1);
                } else {
                    GetShoppingCarList(REFRESH);
                    shoppingCarListWholesaleInfoList.clear();
                    CommonUtil.showToast(mActivity, errmsg);
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
                CommonUtil.showToast(mActivity, "网络连接失败");
            }
        });
    }


    @Override
    public void onResume() {
        super.onResume();
        if (login_flag == 0)
            GetShoppingCarList(REFRESH);
        Log.e("url", "ShoppingCar_Fg_onResume");
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.e("url", "ShoppingCar_Fg_onPause");
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.e("url", "ShoppingCar_Fg_onStop");
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 3:
                if (resultCode == Activity.RESULT_OK) {
                    GetShoppingCarList(REFRESH);
                }
                break;
        }
    }
}
